package com.idata.controller;

import cn.hutool.core.collection.ListUtil;
import com.idata.common.constant.Result;
import com.idata.model.request.IdCardRequest;
import com.idata.model.request.StatisticsRequest;
import com.idata.model.response.CitizenSearchResponse;
import com.idata.model.response.DisputeRelationResponse;
import com.idata.model.response.DisputeStatisticsResponse;
import com.idata.model.response.GraphStatisticsResponse;
import com.idata.service.services.PortaitAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/portraitAnalysis")
public class PortraitAnalysisController {

    @Autowired
    private PortaitAnalysisService portaitAnalysisService;

    @PostMapping("/citizenInfo")
    @ResponseBody
    public Result<CitizenSearchResponse> getBaseInfo(@RequestBody IdCardRequest idCardRequest) {
        CitizenSearchResponse result = portaitAnalysisService.getBaseInfo(idCardRequest.getIdCard());
        return Result.success(result);
    }

    @PostMapping("/graphStatistics")
    @ResponseBody
    public Result<GraphStatisticsResponse> getGraphStatistics(@RequestBody StatisticsRequest statisticsRequest) {
        GraphStatisticsResponse graphStatistics = portaitAnalysisService.getGraphStatistics(statisticsRequest);
        return Result.success(graphStatistics);
    }

    @PostMapping("/disputeRelation")
    @ResponseBody
    public Result<List<DisputeRelationResponse>> getDisputeRelation(@RequestBody StatisticsRequest statisticsRequest) {
        List<DisputeRelationResponse> disputeRelations = portaitAnalysisService.getDisputeRelation(
                ListUtil.toList(statisticsRequest.getIdCard()), statisticsRequest.getStatisticsType()).get(statisticsRequest.getIdCard());
        return Result.success(disputeRelations);
    }

    // todo 逻辑待补充
    @PostMapping("/disputeStatistics")
    @ResponseBody
    public Result<DisputeStatisticsResponse> getDisputeStatistics(@RequestBody IdCardRequest idCardRequest) {
        DisputeStatisticsResponse disputeStatistics = portaitAnalysisService.getDisputeStatistics(idCardRequest);
        return Result.success(disputeStatistics);
    }

    @PostMapping("/disputeHistory")
    @ResponseBody
    public Result<List<Object>> getDisputeHistory(@RequestBody StatisticsRequest statisticsRequest) {
        List<Object> disputeHistoryList = portaitAnalysisService.getDisputeHistory(statisticsRequest);
        return Result.success(disputeHistoryList);
    }

}
